const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const errorHandler = require('./middleware/errorHandler');

const usersRouter = require('./routes/users');
const postsRouter = require('./routes/posts');
const likesRouter = require('./routes/likes');
const commentsRouter = require('./routes/comments');
const followersRouter = require('./routes/followers');
const messagesRouter = require('./routes/messages');
const groupChatsRouter = require('./routes/groupChats');
const notificationsRouter = require('./routes/notifications');
const hashtagsRouter = require('./routes/hashtags');
const bookmarksRouter = require('./routes/bookmarks');

const app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/api/users', usersRouter);
app.use('/api/posts', postsRouter);
app.use('/api/likes', likesRouter);
app.use('/api/comments', commentsRouter);
app.use('/api/followers', followersRouter);
app.use('/api/messages', messagesRouter);
app.use('/api/group-chats', groupChatsRouter);
app.use('/api/notifications', notificationsRouter);
app.use('/api/hashtags', hashtagsRouter);
app.use('/api/bookmarks', bookmarksRouter);

app.use(errorHandler);

module.exports = app;